package com.acme.bankapp.domain.bank;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Bank {
    private List<Client> clients;
    private List<ClientRegistrationListener> listeners;

    private class PrintClientListener implements ClientRegistrationListener {
        public void onClientAdded(Client c) {
            System.out.println(c);
        }
    }

    private class EmailNotificationListener implements ClientRegistrationListener {
        public void onClientAdded(Client c) {
            System.out.println(String.format("Notification email for client %s to be sent", c));
        }
    }

    private class DebugListener implements ClientRegistrationListener {
        public void onClientAdded(Client c) {
            System.out.println(String.format("Debug! Client: %s, Date: %s", c, new Date()));
        }
    }

    public Bank() {
        super();
        clients = new ArrayList<Client>();
        listeners = new ArrayList<ClientRegistrationListener>();
        listeners.add(new EmailNotificationListener());
        listeners.add(new PrintClientListener());
        listeners.add(new DebugListener());
    }

    public Bank(List<ClientRegistrationListener> listeners) {
        this();
        for (ClientRegistrationListener listener: listeners) {
            addClientRegListener(listener);
        }
    }

    public Client addClient(Client client) {
        clients.add(client);
        for (ClientRegistrationListener listener : listeners) {
            listener.onClientAdded(client);
        }
        return client;
    }

    public List<Client> getClients() {
        return new ArrayList<Client>(clients);
    }

    public void addClientRegListener(ClientRegistrationListener listener) {
        listeners.add(listener);
    }
}
